<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="200px">
      
      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['homestay:basic:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['homestay:basic:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['homestay:basic:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['homestay:basic:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="basicList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <!-- <el-table-column label="用户ID" align="center" prop="userId" /> -->
      <!-- <el-table-column label="商家ID" align="center" prop="merchantId" /> -->
      <el-table-column label="地址" align="center" prop="address" />
      <el-table-column label="电话" align="center" prop="telephone" />
      <!-- <el-table-column label="描述" align="center" prop="describe" /> -->

      <!-- <el-table-column label="订房必读-城市通知" align="center" prop="requiredReadCityNotice" /> -->
      <el-table-column label="入住时间" align="center" prop="enterTime" />

      <el-table-column label="离开时间" align="center" prop="leaveTime" />

      <!-- <el-table-column label="入住提示" align="center" prop="enterReminder" />
      <el-table-column label="宠物须知" align="center" prop="petNotice" />
      <el-table-column label="早餐须知" align="center" prop="breakfastNotice" />
      <el-table-column label="预订提示" align="center" prop="bookTips" />
      <el-table-column label="收费说明" align="center" prop="feeDescription" /> -->

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <!-- <el-icon
        ><View />
          </el-icon> -->
          <el-button
            type="text"
            icon="el-icon-view"
            @click="handleDetails(scope.row)"
            v-hasPermi="['homestay:basic:query']"
          >查看详情</el-button>
          
          <el-button
 
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['homestay:basic:edit']"
          >修改</el-button>
          <el-button
   
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['homestay:basic:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改民宿基础信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="商家ID" prop="merchantId">
          <el-input v-model="form.merchantId" placeholder="请输入商家ID" />
        </el-form-item> -->
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="电话" prop="telephone">
          <el-input v-model="form.telephone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="描述" prop="describe">
          <!-- <el-input v-model="form.describe" placeholder="请输入描述" /> -->
          <el-input
            v-model="form.describe"
            style="width: 350px"
            :autosize="{ minRows: 2, maxRows: 4 }"
            type="textarea"
            placeholder="请输入描述"
          />
        </el-form-item>
        <!-- <el-form-item label="订房必读-特殊入离时间" prop="requiredReadTime">
          <el-input v-model="form.requiredReadTime" placeholder="请输入订房必读-特殊入离时间" />
        </el-form-item> -->
        <el-form-item label="订房必读-城市通知" prop="requiredReadCityNotice">
          <el-input
            v-model="form.requiredReadCityNotice"
            style="width: 350px"
            :autosize="{ minRows: 3, maxRows: 4 }"
            type="textarea"
            placeholder="请输入订房必读-城市通知"
          />
        </el-form-item>
        <el-form-item label="入住时间" prop="enterTime">
          <div class="example-basic">
            <el-time-picker v-model="form.enterTime" 
              placeholder="请选择入住时间" 
              format="HH:mm:ss"
              value-format="HH:mm:ss"/>
          </div>
        </el-form-item>

        <el-form-item label="离开时间" prop="leaveTime">
          <div class="example-basic">
            <el-time-picker v-model="form.leaveTime" 
              placeholder="请选择离开时间" 
              format="HH:mm:ss"
              value-format="HH:mm:ss"/>
          </div>
        </el-form-item>

        <el-form-item label="入住提示" prop="enterReminder">
          <el-input
            v-model="form.enterReminder"
            style="width: 350px"
            :autosize="{ minRows: 2, maxRows: 4 }"
            type="textarea"
            placeholder="请输入入住提示"
          />
        </el-form-item>
        <el-form-item label="宠物须知" prop="petNotice">
          <el-input
            v-model="form.petNotice"
            style="width: 350px"
            :autosize="{ minRows: 2, maxRows: 4 }"
            type="textarea"
            placeholder="请输入宠物须知"
          />
        </el-form-item>
        <el-form-item label="早餐须知" prop="breakfastNotice">
          <el-input
            v-model="form.breakfastNotice"
            style="width: 350px"
            :autosize="{ minRows: 2, maxRows: 4 }"
            type="textarea"
            placeholder="请输入早餐须知"
          />
        </el-form-item>
        <el-form-item label="预订提示" prop="bookTips">
          <el-input
            v-model="form.bookTips"
            style="width: 350px"
            :autosize="{ minRows: 2, maxRows: 4 }"
            type="textarea"
            placeholder="请输入预订提示"
          />
        </el-form-item>
        <el-form-item label="收费说明" prop="feeDescription">
          <el-input
            v-model="form.feeDescription"
            style="width: 350px"
            :autosize="{ minRows: 2, maxRows: 4 }"
            type="textarea"
            placeholder="请输入收费说明"
          />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看民宿基础信息对话框 -->
    <el-dialog :title="title" :visible.sync="detailsOpen" width="600px" append-to-body>
      <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="80px">

        <el-form-item label="地址" prop="address">
          <el-input v-model="detailForm.address" placeholder="请输入地址" disabled/>
        </el-form-item>
        <el-form-item label="电话" prop="telephone">
          <el-input v-model="detailForm.telephone" placeholder="请输入电话" disabled/>
        </el-form-item>
        <el-form-item label="描述" prop="describe">
          <!-- <el-input v-model="form.describe" placeholder="请输入描述" /> -->
          <el-input
            v-model="detailForm.describe"
            style="width: 350px"
            :autosize="{ minRows: 2, maxRows: 4 }"
            type="textarea" disabled
          />
        </el-form-item>
        <!-- <el-form-item label="订房必读-特殊入离时间" prop="requiredReadTime">
          <el-input v-model="form.requiredReadTime" placeholder="请输入订房必读-特殊入离时间" />
        </el-form-item> -->
        <el-form-item label="订房必读-城市通知" prop="requiredReadCityNotice">
          <el-input
            v-model="detailForm.requiredReadCityNotice"
            style="width: 350px"
            :autosize="{ minRows: 3, maxRows: 4 }"
            type="textarea"
            disabled
          />
        </el-form-item>
        <el-form-item label="入住时间" prop="enterTime">
          <div class="example-basic">
            <el-time-picker v-model="detailForm.enterTime" 
            disabled
              format="HH:mm:ss"
              value-format="HH:mm:ss"/>
          </div>
        </el-form-item>

        <el-form-item label="离开时间" prop="leaveTime">
          <div class="example-basic">
            <el-time-picker v-model="detailForm.leaveTime" 
            disabled
              format="HH:mm:ss"
              value-format="HH:mm:ss"/>
          </div>
        </el-form-item>

        <el-form-item label="入住提示" prop="enterReminder">
          <el-input
            v-model="detailForm.enterReminder"
            style="width: 350px"
            :autosize="{ minRows: 2, maxRows: 4 }"
            type="textarea"
            disabled
          />
        </el-form-item>
        <el-form-item label="宠物须知" prop="petNotice">
          <el-input
            v-model="detailForm.petNotice"
            style="width: 350px"
            :autosize="{ minRows: 2, maxRows: 4 }"
            type="textarea"
            disabled
          />
        </el-form-item>
        <el-form-item label="早餐须知" prop="breakfastNotice">
          <el-input
            v-model="detailForm.breakfastNotice"
            style="width: 350px"
            :autosize="{ minRows: 2, maxRows: 4 }"
            type="textarea"
            disabled
          />
        </el-form-item>
        <el-form-item label="预订提示" prop="bookTips">
          <el-input
            v-model="detailForm.bookTips"
            style="width: 350px"
            :autosize="{ minRows: 2, maxRows: 4 }"
            type="textarea"
            disabled
          />
        </el-form-item>
        <el-form-item label="收费说明" prop="feeDescription">
          <el-input
            v-model="detailForm.feeDescription"
            style="width: 350px"
            :autosize="{ minRows: 2, maxRows: 4 }"
            type="textarea"
            disabled
          />
        </el-form-item>

      </el-form>

    </el-dialog>
  </div>
</template>

<script>
import { listBasic, getBasic, delBasic, addBasic, updateBasic } from "@/api/homestay/basic";

export default {
  name: "Basic",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 民宿基础信息表格数据
      basicList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否展示详情
      detailsOpen: false,
      detailForm: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        merchantId: null,
        address: null,
        telephone: null,
        describe: null,
        requiredReadTime: null,
        requiredReadCityNotice: null,
        enterTime: null,
        leaveTime: null,
        enterReminder: null,
        petNotice: null,
        breakfastNotice: null,
        bookTips: null,
        feeDescription: null,
        deleteFlag: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询民宿基础信息列表 */
    getList() {
      this.loading = true;
      listBasic(this.queryParams).then(response => {
        this.basicList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        merchantId: null,
        address: null,
        telephone: null,
        describe: null,
        requiredReadTime: null,
        requiredReadCityNotice: null,
        enterTime: null,
        leaveTime: null,
        enterReminder: null,
        petNotice: null,
        breakfastNotice: null,
        bookTips: null,
        feeDescription: null,
        deleteFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加民宿基础信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBasic(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改民宿基础信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      console.log(this.form)
      this.$refs["form"].validate(valid => {

        if (valid) {
          if (this.form.id != null) {
            updateBasic(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBasic(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除该民宿基础信息？').then(function() {
        return delBasic(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/basic/export', {
        ...this.queryParams
      }, `basic_${new Date().getTime()}.xlsx`)
    },
    /** 查看详情 */
    handleDetails(row) {
      const id = row.id 
      this.detailsOpen = true;
      getBasic(id).then(response => {
        this.detailForm = response.data
      });
    }
  },
  
};
</script>
